﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using CE.Global;
using CE.User;
using CE.Database;
using CE.CarInsurance;

public partial class User_Details : MyLanguageBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            if (Session[CE.Global.General.UserId] == null)
                Response.Redirect("login.aspx");
            
            
            General.ClearAllSession(Page, "ALL");
            UserResultDataBind();
            //CRMResultDataBind();
            //LogUserViewedHistory();

            //if (dtlUserResult.Items.Count == 0 && dtlUserResultCRM.Items.Count == 0)

            if (dtlUserResult.Items.Count == 0)
                lblResultHistoryMessage.Text = Resources.Menu.ViewHistory; //"There is no record in quotes history.";
            else
                lblResultHistoryMessage.Text = "";
        }
    }

    private void LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        _userviewdb.LogViewedHistory("UIB", Request, "View user insurance bought.");
    }

    private ICollection CreateDatasource(string ResultType, int ResultRowCount)
    {
        UserResultHistoryDB _resultdb = new UserResultHistoryDB();
        DataTable _dt = new DataTable("ResultTable");
        _dt = _resultdb.GetResultHistoryCompletedTable(Convert.ToInt64(Session[General.UserId].ToString()), ResultType);
        //_dt = _resultdb.GetResultHistoryTable(Convert.ToInt64(Session[General.UserId].ToString()), ResultType);
        DataView _dv = new DataView(_dt);
        return _dv;
    }

    protected void dtlUserResult_ItemCommand(object source, DataListCommandEventArgs e)
    {
        //Response.Write("Show Result : " + dtlUserResult.DataKeys[e.Item.ItemIndex].ToString());

        //int index = Convert.ToInt32(e.CommandArgument);

        if (Session[General.UserId] == null)
        {
            Response.Redirect("login.aspx");
        }

        if (e.Item != null && e.Item.ItemIndex >= 0)
        {
            Int64 _resultId = Convert.ToInt64(dtlUserResult.DataKeys[e.Item.ItemIndex].ToString());

            Int64 _userId = Convert.ToInt64(Session[General.UserId].ToString());

            //Response.Write(_resultId.ToString());

            UserResultHistory _resulthis = new UserResultHistory();
            UserResultHistoryDB _resulthisdb = new UserResultHistoryDB();

            _resulthis = _resulthisdb.GetResultHistory(_userId, _resultId);
            if (_resulthis != null)
            {
                if (e.CommandName == "ShowSavedQuote")
                {
                    if (_resulthis.ResultType == "CI")
                    {
                        //Session["ViewCIResultId"] = _resultId.ToString();
                        Response.Redirect("user_insurancedetails.aspx?vcid=" + _resultId.ToString());

                    }

                }
            }
        }
    }

    protected void dtlUserResult_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Panel _pnlQuote = (Panel)e.Item.FindControl("pnlQuote");
            if (_pnlQuote != null)
            {
                _pnlQuote.Attributes.Add("onmouseover", "javascript:orgBgColor = this.className; this.className = 'quote_over';");
                _pnlQuote.Attributes.Add("onmouseout", "javascript:this.className = orgBgColor;");
            }

            Int64 _NomGG = 0;
            Int64 CustomerId = 0;
            if (Session[CE.Global.General.UserId] != null)
            {
                CustomerId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
            }
            Int64 CECarId = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID1"].ToString());
            DataSet _dsNonGG = new DataSet();
            _dsNonGG = GetCarDetails(CECarId, CustomerId);
            if (_dsNonGG != null && _dsNonGG.Tables.Count > 2 && _dsNonGG.Tables[2].Rows.Count > 0)
            {
                _NomGG = 1;
            }
            Button ibtTempResult = (Button)e.Item.FindControl("ibtShowResult");
            //Button ibtTempEditDetail = (Button)e.Item.FindControl("ibtEditDetail");

            Button ibtTempDelete = (Button)e.Item.FindControl("ibtDeleteResult");

            Button ibtRerunQuotes = (Button)e.Item.FindControl("ibtRerunQuotes"); // Sakthi
            Button ibtDeleteResult2 = (Button)e.Item.FindControl("ibtDeleteResult2"); // Sakthi
            //divItemMessage
            //Label lblUserName = (Label)e.Item.FindControl("lblUserName");
            Label lblQuoteTitle = (Label)e.Item.FindControl("lblQuoteTitle");
            Label lblInsuranceType = (Label)e.Item.FindControl("lblInsuranceType");
            Label lblGarageType = (Label)e.Item.FindControl("lblGarageType");
            Label lblVehicleType = (Label)e.Item.FindControl("lblVehicleType");
            //Label lblItmMessage = (Label)e.Item.FindControl("lblItemMessage");
            Label lblCompleteDate = (Label)e.Item.FindControl("lblCompleteDate");
            Label lblPolicyStartDate = (Label)e.Item.FindControl("lblPolicyStartDate");
            Label lblStatus = (Label)e.Item.FindControl("lblStatus");

            //Sakthi on 21 Jun 2012 Start
            //Int64 _resultId = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["UserResultId"].ToString());
            //string _rowguid = ((DataRowView)(e.Item.DataItem)).Row["RowGUID"].ToString();
            //string _status = ((DataRowView)(e.Item.DataItem)).Row["Status"].ToString();

            //DateTime _dtDateComplete = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["CreatedDate"].ToString());
            //DateTime _dtPolicyStartDate = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["ModifiedDate"].ToString());
            //string _resulttype = ((DataRowView)(e.Item.DataItem)).Row["ResultType"].ToString();
            //bool _iscomplete = Convert.ToBoolean(((DataRowView)(e.Item.DataItem)).Row["IsComplete"].ToString());
            //HtmlGenericControl _divPartial = (HtmlGenericControl)e.Item.FindControl("divPartialButton");
            //HtmlGenericControl _divComplete = (HtmlGenericControl)e.Item.FindControl("divCompleteButton");
            //HtmlGenericControl _divPartial2 = (HtmlGenericControl)e.Item.FindControl("divPartialButton2");

            Int64 _resultId = 0;
            string _rowguid = "";
            string _status = "";

            DateTime _dtDateComplete = DateTime.Now;
            DateTime _dtPolicyStartDate = DateTime.Now;
            string _resulttype = "CI";
            bool _iscomplete = false;
            HtmlGenericControl _divPartial = (HtmlGenericControl)e.Item.FindControl("divPartialButton");
            HtmlGenericControl _divComplete = (HtmlGenericControl)e.Item.FindControl("divCompleteButton");
            HtmlGenericControl _divPartial2 = (HtmlGenericControl)e.Item.FindControl("divPartialButton2");

            if (_dsNonGG != null && _dsNonGG.Tables.Count > 2 && _dsNonGG.Tables[2].Rows.Count > 0)
            {                
                _resultId = 0;
                _rowguid = "0";
                _status = "Complete";

                _dtDateComplete = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["CreatedDate"].ToString());
                if (_dsNonGG.Tables[2].Rows[0]["CoverageStart"] != DBNull.Value && _dsNonGG.Tables[2].Rows[0]["CoverageStart"].ToString() != string.Empty)
                    _dtPolicyStartDate = Convert.ToDateTime(_dsNonGG.Tables[2].Rows[0]["CoverageStart"].ToString());
                _resulttype = ((DataRowView)(e.Item.DataItem)).Row["ResultType"].ToString();
                _iscomplete = true;
            }
            else
            {
                _resultId = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["UserResultId"].ToString());
                _rowguid = ((DataRowView)(e.Item.DataItem)).Row["RowGUID"].ToString();
                _status = ((DataRowView)(e.Item.DataItem)).Row["Status"].ToString();

                _dtDateComplete = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["CreatedDate"].ToString());
                _dtPolicyStartDate = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["ModifiedDate"].ToString());
                _resulttype = ((DataRowView)(e.Item.DataItem)).Row["ResultType"].ToString();
                _iscomplete = Convert.ToBoolean(((DataRowView)(e.Item.DataItem)).Row["IsComplete"].ToString());
            }
            //Sakthi on 21 Jun 2012 End
            if (_status.ToUpper() == "COMPLETE")
            {
                _pnlQuote.Visible = true;
                lblQuoteTitle.Visible = true;
                
                lblStatus.Text = _status + "d Quote";
                lblStatus.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                _pnlQuote.Visible = false;
                lblQuoteTitle.Visible = false;

                lblStatus.Text = _status + " Quote";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }

            lblCompleteDate.Text = _dtDateComplete.ToString("dd/MMM/yyyy");
            lblPolicyStartDate.Text = _dtPolicyStartDate.ToString("dd/MMM/yyyy");

            if (_resulttype == "CI")
            {
                string _cardescription = ((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString();
                string _insuranceype = ((DataRowView)(e.Item.DataItem)).Row["Info2"].ToString();
                string _garageType = ((DataRowView)(e.Item.DataItem)).Row["Info3"].ToString();
                string _vehicleUsage = ((DataRowView)(e.Item.DataItem)).Row["Info4"].ToString();
                Int64 _ID1 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID1"].ToString());
                Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
                Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();
                string _carmodel = "";

                if (_cardescription != string.Empty)
                {
                    _carmodel = _cardescription;
                }

                bool _requestStatus = true;
                DateTime _todayDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                _todayDate = _todayDate.AddDays(-14);
                if (_todayDate.CompareTo(_dtDateComplete) > 0)
                {
                    _requestStatus = false;
                }
                else
                {
                    _requestStatus = true;
                }

                bool _commenceStatus = true;
                DateTime _today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                if (_today.CompareTo(_dtPolicyStartDate) >= 0)
                {
                    _commenceStatus = false;
                }
                else
                {
                    _commenceStatus = true;
                }

                if (_garageType == "1")
                {
                    lblGarageType.Text = Resources.CarInsurance.Garage_Authorized;
                }
                else if (_garageType == "2")
                {
                    lblGarageType.Text = Resources.CarInsurance.Garage_Dealer;
                }

                if (_insuranceype == "10")
                {
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOne;
                }
                else if (_insuranceype == "11")
                {
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOneLowCost;
                }
                else if (_insuranceype == "21")
                {
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
                }
                else if (_insuranceype == "30")
                {
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThree;
                }
                else if (_insuranceype == "31")
                {
                    lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
                }


                if (_vehicleUsage == "110")
                {
                    lblVehicleType.Text = Resources.CarInsurance.VehicleType_Private;
                }
                else if (_vehicleUsage == "120")
                {
                    lblVehicleType.Text = Resources.CarInsurance.VehicleType_Commercial;
                }

                if (_iscomplete == true)
                {
                    string _providerId = "0";
                    if (_NomGG == 1)
                    {
                        _providerId = _dsNonGG.Tables[2].Rows[0]["ProviderCompanyId"].ToString();
                    }
                    else
                    {
                        MyDatabase _db = new MyDatabase();
                        string strSql = "SELECT ProviderCompanyId FROM [tblCarInsuranceSelectItemTH] WHERE CarId = " + _ID1 + " AND [Status] = 1";
                        _providerId = _db.ExecuteScalarSqlStatement(strSql).ToString();
                    }
                    _refno = General.GetRefNumber(_ID1);


                    if (_providerId == "11")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : AZC" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "12")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : MSI" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "16")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : AXA" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "29")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : LMG" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "31")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : CTS" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "32")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : BKI" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "33")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : MTI" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "35")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : KPI" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "39")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : MIR" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "41")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : KUR" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "43")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : SMK" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "45")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : VRY" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }
                    else if (_providerId == "46")
                    {
                        lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : TMS" + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;
                    }


                    ibtTempResult.Enabled = false;

                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false; //Sakthi
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    if (_requestStatus == true)
                    {
                        _divPartial.Visible = true;
                        _divPartial2.Visible = false;
                    }
                    else
                    {
                        _divPartial.Visible = false;
                        _divPartial2.Visible = true;
                    }

                    if (_commenceStatus == true)
                    {
                        _divPartial.Visible = true;
                        _divPartial2.Visible = false;
                    }
                    else
                    {
                        _divPartial.Visible = false;
                        _divPartial2.Visible = true;
                    }

                    lblQuoteTitle.Text = Resources.CarInsurance.CarInsuranceList + ":" + _carmodel;


                    if (_ID2 != 0)
                    {
                        //ibtTempDelete.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _carmodel + "\"?')");
                        //ibtDeleteResult2.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _carmodel + "\"?')"); //Sakthi
                        ibtTempDelete.Attributes.Add("OnClick", "javascript:if (confirm('Are you sure to delete \"" + _carmodel + "\"?')) { this.className='button_w_processing';return true; } else { return false; }");
                        ibtDeleteResult2.Attributes.Add("OnClick", "javascript:if (confirm('Are you sure to delete \"" + _carmodel + "\"?')) { this.className='button_w_processing';return true; } else { return false; }");

                    }
                }
            }
            #region Removed on 07 Mar 2012 by Sakthi
            /*else if (_resulttype == "HF")
            {
                string _hfdescription = ((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString() + "-";
                _hfdescription += ((DataRowView)(e.Item.DataItem)).Row["Info2"].ToString() + "-";
                _hfdescription += ((DataRowView)(e.Item.DataItem)).Row["Info3"].ToString();

                Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
                Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();

                if (_iscomplete == true)
                {
                    lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refno + " - Home Refinance (" + _hfdescription + ")";

                    ibtTempResult.Enabled = false;
                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false;//Sakthi
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    lblQuoteTitle.Text = "Home Refinance (" + _hfdescription + ")";
                    if (_ID2 != 0)
                    {
                        ibtTempDelete.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _hfdescription + "\"?')");
                    }
                }
            }
            else if (_resulttype == "CC")
            {
                string _ccdescription = ((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString() + "-";
                _ccdescription += ((DataRowView)(e.Item.DataItem)).Row["Info2"].ToString();
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();

                if (_iscomplete == true)
                {
                    lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refno + " - Credit Cards (" + _ccdescription + ")";

                    ibtTempResult.Enabled = false;
                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false;//Sakthi
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    lblQuoteTitle.Text = "Credit Cards (" + _ccdescription + ")";
                }
            }
            else if (_resulttype == "PL")
            {
                Int32 _pltype = Convert.ToInt32(((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString());
                string _pldescription = "";

                if (_pltype == 1)
                {
                    _pldescription = "Type : " + "Personal Loan";
                    _pldescription += " - Amount : " + ((DataRowView)(e.Item.DataItem)).Row["Info2"].ToString();
                    _pldescription += " - Period : " + ((DataRowView)(e.Item.DataItem)).Row["Info3"].ToString() + " Years";
                }
                else
                {
                    _pldescription = "Type : " + "Personal Line of Credit";
                    _pldescription += " - Amount : " + ((DataRowView)(e.Item.DataItem)).Row["Info2"].ToString();
                }

                Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
                Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();

                if (_iscomplete == true)
                {
                    lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refno + " - Personal Loans (" + _pldescription + ")";

                    ibtTempResult.Enabled = false;
                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false;
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    lblQuoteTitle.Text = "Personal Loans (" + _pldescription + ")";
                    if (_ID2 != 0)
                    {
                        ibtTempDelete.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _pldescription + "\"?')");
                    }
                }
            }
            else if (_resulttype == "PA")
            {
                string _padescription = ((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString();

                Int64 _ID1 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID1"].ToString());
                Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
                Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();

                if (_iscomplete == true)
                {
                    //lblQuoteTitle.Text = "Quote Ref No : " + _refno + " - Personal Accidents (" + _padescription + ")";
                    MyDatabase _db = new MyDatabase();
                    string strSql = "SELECT ProviderCompanyId FROM tblPAInsuranceSelectItem WHERE PAId = " + _ID1 + " AND PASelectItemId = " + _ID2;
                    string _providerId = _db.ExecuteScalarSqlStatement(strSql).ToString();

                    _refno = General.GetRefNumber(_ID1);

                    if (_providerId == "23")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : PAH" + _refno + " - Personal Accidents (" + _padescription + ")";
                    }
                    else if (_providerId == "29")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : PAL" + _refno + " - Personal Accidents (" + _padescription + ")";
                    }
                    else if (_providerId == "34")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : PAC" + _refno + " - Personal Accidents (" + _padescription + ")";
                    }
                    else if (_providerId == "35")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : PAQ" + _refno + " - Personal Accidents (" + _padescription + ")";
                    }
                    else if (_providerId == "30")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : PAE" + _refno + " - Personal Accidents (" + _padescription + ")";
                    }

                    ibtTempResult.Enabled = false;
                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false;
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    
                    lblQuoteTitle.Text = "Personal Accidents (" + _padescription + ")";
                    if (_ID2 != 0)
                    {
                        ibtTempDelete.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _padescription + "\"?')");
                    }
                }
            }
            else if (_resulttype == "TA")
            {
                string _tadescription = ((DataRowView)(e.Item.DataItem)).Row["Info1"].ToString();

                Int64 _ID1 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID1"].ToString());
                Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
                Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
                string _refno = ((DataRowView)(e.Item.DataItem)).Row["Info10"].ToString();

                if (_iscomplete == true)
                {
                    MyDatabase _db = new MyDatabase();
                    string strSql = "select ninfo2 from tblTAApplicantSearch where TAAppSeaId = " + _ID1;
                    string _providerId = _db.ExecuteScalarSqlStatement(strSql).ToString();

                    _refno = General.GetRefNumber(_ID1);

                    if (_providerId == "23")
                    {                        
                        lblQuoteTitle.Text = "Quote Ref No : TIH" + _refno + " - Travel Insurance (" + _tadescription + ")";
                    }
                    else if (_providerId == "29")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : TIL" + _refno + " - Travel Insurance (" + _tadescription + ")";
                    }
                    else if (_providerId == "34")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : TIC" + _refno + " - Travel Insurance (" + _tadescription + ")";
                    }
                    else if (_providerId == "35")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : TIQ" + _refno + " - Travel Insurance (" + _tadescription + ")";
                    }
                    else if (_providerId == "36")
                    {
                        lblQuoteTitle.Text = "Quote Ref No : TIA" + _refno + " - Travel Insurance (" + _tadescription + ")";
                    }
                   
                   
                   

                    ibtTempResult.Enabled = false;
                    ibtTempDelete.Enabled = false;

                    _divPartial.Visible = false;
                    _divComplete.Visible = true;

                    _divPartial2.Visible = false;
                    ibtRerunQuotes.Enabled = false;
                }
                else
                {
                    lblQuoteTitle.Text = "Travel Insurance (" + _tadescription + ")";

                    if (_ID1 != 0)
                    {
                        ibtTempDelete.Attributes.Add("onclick", "return confirm('Are you sure to delete \"" + _tadescription + "\"?')");
                    }
                }


            } */
            #endregion
        }
    }

    private void UserResultDataBind()
    {
        if (Page.Request["resulttype"] != null)
        {
            dtlUserResult.DataSource = CreateDatasource(Page.Request["resulttype"].ToString(), 10);
            dtlUserResult.DataBind();

        }
        else
        {
            //Sakthi on 08 Feb 2011 - start
            //dtlUserResult.DataSource = CreateDatasource("ALL", 5);
            dtlUserResult.DataSource = CreateDatasource("CI", 5);
            //Sakthi on 08 Feb 2011 - End
            dtlUserResult.DataBind();

        }
        General.ClearAllSession(this.Page, "AL");
    }

    public DataSet GetCarDetails(Int64 CarId, Int64 CustomerId)
    {
        MyDatabase _db = new MyDatabase();
        string _spName = "[sprocCXCRMNONGGPackageCarDetailsSelectedItemByCarId]";

        SortedList _spara = new SortedList();
        _spara.Add("@CarId", CarId);
        _spara.Add("@CustomerId", CustomerId);

        DataSet _ds = _db.GetDataSet(_spName, _spara);

        return _ds;
    }

    private void CRMResultDataBind()
    {
        CarInsuranceCompletedItemDB cardb = new CarInsuranceCompletedItemDB();
        DataSet dsCRM = new DataSet();

        int userid = 0;
        if (Session[CE.Global.General.UserId] != null)
            userid = int.Parse(Session[CE.Global.General.UserId].ToString());

        dsCRM = cardb.GetCRMCompletedItem(userid);

        if (dsCRM.Tables[0].Rows.Count > 0)
        {
            dtlUserResultCRM.DataSource = dsCRM.Tables[0];
            dtlUserResultCRM.DataBind();
        }
        else
            dtlUserResultCRM.Visible = false;
        
    }

    protected void dtlUserResultCRM_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (Session[General.UserId] == null)
        {
            Response.Redirect("login.aspx");
        }

        if (e.Item != null && e.Item.ItemIndex >= 0)
        {
            Int64 _carid = Convert.ToInt64(dtlUserResultCRM.DataKeys[e.Item.ItemIndex].ToString());

            if (e.CommandName == "ShowSavedQuote")
            {
                Response.Redirect("user_insurancedetails.aspx?cid=" + _carid.ToString());
                
            }
        }
    }

    protected void dtlUserResultCRM_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Panel _pnlQuote = (Panel)e.Item.FindControl("pnlQuote");
            if (_pnlQuote != null)
            {
                _pnlQuote.Attributes.Add("onmouseover", "javascript:orgBgColor = this.className; this.className = 'quote_over';");
                _pnlQuote.Attributes.Add("onmouseout", "javascript:this.className = orgBgColor;");
            }

            Button ibtTempResult = (Button)e.Item.FindControl("ibtShowResult");          
            Label lblQuoteTitle = (Label)e.Item.FindControl("lblQuoteTitle");
            Label lblInsuranceType = (Label)e.Item.FindControl("lblInsuranceType");
            Label lblGarageType = (Label)e.Item.FindControl("lblGarageType");
            Label lblVehicleType = (Label)e.Item.FindControl("lblVehicleType");
            Label lblCompleteDate = (Label)e.Item.FindControl("lblCompleteDate");
            Label lblPolicyStartDate = (Label)e.Item.FindControl("lblPolicyStartDate");
            Label lblStatus = (Label)e.Item.FindControl("lblStatus");

            string _cardescription = ((DataRowView)(e.Item.DataItem)).Row["CarModel"].ToString();
            string _insurancetype = ((DataRowView)(e.Item.DataItem)).Row["InsuranceType"].ToString();
            string _garageType = ((DataRowView)(e.Item.DataItem)).Row["GarageType"].ToString();
            string _vehicleUsage = ((DataRowView)(e.Item.DataItem)).Row["VehicleType"].ToString();
            //Int64 _ID1 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID1"].ToString());
            //Int64 _ID2 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID2"].ToString());
            //Int64 _ID3 = Convert.ToInt64(((DataRowView)(e.Item.DataItem)).Row["ID3"].ToString());
            string _refno = ((DataRowView)(e.Item.DataItem)).Row["QuoteRefNo"].ToString();
            DateTime _dtcoveragestart = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["CoverageStart"].ToString());
            DateTime _dtDateComplete = Convert.ToDateTime(((DataRowView)(e.Item.DataItem)).Row["CreatedDate"].ToString());
            string _carmodel = "";

            if (_garageType == "1")
            {
                lblGarageType.Text = Resources.CarInsurance.Garage_Authorized;
            }
            else if (_garageType == "2")
            {
                lblGarageType.Text = Resources.CarInsurance.Garage_Dealer;
            }

            if (_vehicleUsage == "110")
            {
                lblVehicleType.Text = Resources.CarInsurance.VehicleType_Private;
            }
            else if (_vehicleUsage == "120")
            {
                lblVehicleType.Text = Resources.CarInsurance.VehicleType_Commercial;
            }

            if (_cardescription != string.Empty)
            {
                _carmodel = _cardescription;
            }

            if (_insurancetype == "10")
            {
                lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOne;
            }
            else if (_insurancetype == "11")
            {
                lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassOneLowCost;
            }
            else if (_insurancetype == "21")
            {
                lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassTwoPlus;
            }
            else if (_insurancetype == "30")
            {
                lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThree;
            }
            else if (_insurancetype == "31")
            {
                lblInsuranceType.Text = Resources.CarInsurance.Insurance_ClassThreePlus;
            }

            lblQuoteTitle.Text = Resources.CarInsurance.QuoteRefNo + " : " + _refno + " <br/> " + Resources.CarInsurance.CarInsuranceList + " " + _carmodel;

            lblPolicyStartDate.Text = _dtcoveragestart.ToString("dd/MMM/yyyy");
            lblStatus.Text = "Completed Quote";
            lblStatus.ForeColor = System.Drawing.Color.Green;
            lblCompleteDate.Text = _dtDateComplete.ToString("dd/MMM/yyyy");

            HtmlGenericControl _divComplete = (HtmlGenericControl)e.Item.FindControl("divCompleteButton");
            _divComplete.Visible = true;

        }
    }
}
